<?php

class McCube_Theme extends McCube_Html_Abstact{

    protected static $_default   = '';
    protected static $_instances = array();

    protected static $_current = 'classic';
    protected static $_themes  = array(
         'site'    => array('path'=>'/')
        ,'classic' => array('path'=>'/McCube/Theme/classic/', 'object'=> true)
        ,'jquery'  => array('path'=>'/Jquery/', 'object'=> true)
    );
    protected static $_register = array();

    public static function get($name=''){
        if(!$name)
            $name = self::$_current;

        if(!isset(self::$_register[$name]))
            if(isset(self::$_themes[$name]['object'])){
                $classname = 'McCube_Theme_'.ucFirst($name);
                self::$_register[$name] = new $classname($name, self::$_themes[$name]['path']);
            } else {
                self::$_register[$name] = new self($name, self::$_themes[$name]['path']);
            }

        return self::$_register[$name];
    }

    public static function buildJsInstances(){
        $echo = '';
        foreach(self::$_register as $instance){
            $echo .= $instance->buildJsInstance();
        }
        return $echo;
    }

    // --------------------------------------------------

    protected $_name          = '';
    protected $_path          = '';
    protected $_imgExtension  = 'png';
    protected $_iconExtension = 'png';

    public function __construct($name, $path){
        $this->_name = $name;
        $this->_path = $path;
    }

    public function required(){
        return '<script type="text/javascript">'
            .'$.mcCube.theme.instance("'.$this->_name.'", '.json_encode(array(
                'image' => array(
                      'path'      => $this->_path.'images/'
                    , 'extension' => $this->_imgExtension
                )
            )).');'
        .'</script>';
    }

    public function icon($src, $href, $attrsA=array(), $attrsImg=array()){
        return '<a href="'.$href.'"'.parent::buildAttrs($attrsA).'>'
            .$this->img('icons/'.$src, $attrsImg)
        .'</a>';
    }

    public function img($src, $attrs=array()){
        return '<img'
            .parent::buildAttrs($attrs)
            .' src="'.$this->_path.'images/'.$src.'.'.$this->_imgExtension.'"'
        .' />';
    }

    public function css($src, $media="screen", $extension='css'){
        return '<link'
            .' rel="stylesheet" type="text/css"'
            .' href="'.$this->_path.'css/'.$src.'.'.$extension.'" media="'.$media.'"'
            .' />';
    }

    public function js($src, $extension='js'){
        return '<script'
            .' type="text/javascript"'
            .' src="'.$this->_path.'javascript/'.$src.'.'.$extension.'"'
            .' /></script>';
    }

}